<?php
namespace qun\models;

use common\base\BModel;
use Yii;
class IndustryModel extends BModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'industry';
    }

    /**
     * @db
     */
    public static function getDb()
    {
        return Yii::$app->get('qun');
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id','sort','parent_id','type'], 'integer'],
            [['name'], 'string', 'max' => 20],
            [['name'], 'unique'],
            [['name','type'], 'required', 'on' => ['add'], 'message' => '{attribute}不能为空'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '类型名称',
            'sort' => '排序',
            'parent_id' => '0为父级 以下依次',
            'type' => '1一级行业 2二级行业',
        ];
    }

    /**
     * 保存前
     * @param bool $insert
     * @return bool
     */
    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert)){
            $time = time();
            if($this->isNewRecord){
            }
            return true;
        }
        return false;
    }

}
